package com.ruoyi.web.controller.equ;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equ.domain.EquMove;
import com.ruoyi.equ.domain.vo.EquMoveVos;
import com.ruoyi.equ.service.IEquMoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 移动记录Controller
 *
 * @author ruoyi
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/equ/move")
public class EquMoveController extends BaseController
{
    @Autowired
    private IEquMoveService equMoveService;

    /**
     * 查询移动记录列表
     */
    @PreAuthorize("@ss.hasPermi('equ:move:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ModelAttribute EquMove equMove)
    {
        startPage();
        List<EquMove> list = equMoveService.selectEquMoveList(equMove);
        return getDataTable(list);
    }
    /**
     * 查询移动记录列表
     */
    @PreAuthorize("@ss.hasPermi('equ:move:list')")
    @GetMapping("/listVo")
    public TableDataInfo listVo(EquMoveVos equMove)
    {
        startPage();
        List<EquMoveVos> list = equMoveService.selectEquMoveVosList(equMove);
        return getDataTable(list);
    }
    /**
     * 导出移动记录列表
     */
    @PreAuthorize("@ss.hasPermi('equ:move:export')")
    @Log(title = "移动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ModelAttribute EquMove equMove)
    {
        List<EquMove> list = equMoveService.selectEquMoveList(equMove);
        ExcelUtil<EquMove> util = new ExcelUtil<EquMove>(EquMove.class);
        util.exportExcel(response, list, "移动记录数据");
    }

    /**
     * 获取移动记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('equ:move:query')")
    @GetMapping(value = "/{moveId}")
    public AjaxResult getInfo(@PathVariable("moveId") Long moveId)
    {
        return success(equMoveService.selectEquMoveByMoveId(moveId));
    }

    /**
     * 新增移动记录
     */
    @PreAuthorize("@ss.hasPermi('equ:move:add')")
    @Log(title = "移动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquMove equMove)
    {
        return toAjax(equMoveService.insertEquMove(equMove));
    }

    /**
     * 修改移动记录
     */
    @PreAuthorize("@ss.hasPermi('equ:move:edit')")
    @Log(title = "移动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquMove equMove)
    {
        return toAjax(equMoveService.updateEquMove(equMove));
    }

    /**
     * 删除移动记录
     */
    @PreAuthorize("@ss.hasPermi('equ:move:remove')")
    @Log(title = "移动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moveIds}")
    public AjaxResult remove(@PathVariable("moveIds") Long[] moveIds)
    {
        return toAjax(equMoveService.deleteEquMoveByMoveIds(moveIds));
    }
    /**
     * 2.8新增移动记录并修改设备状态
     */
    @Log(title = "移动记录", businessType = BusinessType.INSERT)
    @PostMapping("/finishMoveAndAsset")
    public AjaxResult finishMoveAndAsset(@RequestBody EquMove equMove)
    {
        try {
            Boolean result = equMoveService.finishMoveAndAsset(equMove);
            return AjaxResult.success(result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("操作失败");
        }
    }

    /**
     * 获取移动记录详细信息
     * @param assetId
     * @return List<EquMove>
     */
    @PreAuthorize("@ss.hasPermi('equ:move:query')")
    @GetMapping(value = "/getMoveByAssetId/{assetId}")
    public TableDataInfo getMoveByAssetId(@PathVariable("assetId") Long assetId)
    {   startPage();
        List<EquMove> list = equMoveService.getMovesByAssetId(assetId);
        return getDataTable( list);
    }


}
